mui('body').on('tap','a',function(){
    window.top.location.href=this.href;
});	
function get_code(length){
	if(length == undefined){
		length = 4;
	}
	var pow = Math.pow(10,length);	
	var code = Math.floor(Math.random() * pow + pow / 10).toString();
	return code.substr(0, length);
}

function shopAjax (config) {
	this.options = {
		"method": 'POST',
		"data": '',
		"dataType": 'json',
	};
	$.extend(true, this.options, config);
};

shopAjax.prototype.ajax = function () {
	//var load =  layer.open({type: 2});
	var options = this.options
	$.ajax({
		type: options.method||'post',
		url: options.url,
		dataType: options.dataType||'json',
		data: options.data
	}).done(function (response) {
		if(response.status){
			options.callback(response);
			return true;
		}else{
			mui.toast(response.msg);
		}
	}).fail(function (XMLHttpRequest) {
		if (XMLHttpRequest.status == 422) {
			mui.toast(XMLHttpRequest.responseJSON.msg);
		}else{
			mui.toast('网络异常,请检查连接');
		}
	}).always(function () {
		//layer.close(load);
	});
};

function filterUrl(newData) {
	var url = window.location.href;
	if(!newData || newData == '' || newData == undefined){
		return  url;
	}
	var hostName = url;
	if(url.indexOf("?") >= 1){
		var urlArr = url.split('?')
		hostName = urlArr[0];
		var paramsObj = urlToArr(urlArr[1]);
		if(paramsObj){
			$.extend(paramsObj,newData)
		}
	}else{
		paramsObj = newData;
	}
	return  hostName+"?"+jQuery.param(paramsObj);
}


function urlToArr(uri) {

	uri = decodeURIComponent(uri);
	//拼接数组
	var arrUrl = uri.split('&');
	var urlObj = {};
	var len = arrUrl.length;
	for (var i=0; i<len; i++){
		if(arrUrl[i].indexOf('=')>=1){
			var params = arrUrl[i].split('=');
			if(params[0]!=''&&params[1]!=''){
				urlObj[params[0]] = params[1];
			}
		}
	}

	return $.isEmptyObject(urlObj)?false:urlObj;
}